<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>JS二维码</title>
    <script type="text/javascript" src="../js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../js/jquery.qrcode.min.js"></script>
    <script type="text/javascript">
        function getQRcode() {
            var content = toUtf8($('#content').val());
            $('#qrcode').qrcode({render: "canvas", width: 64, height: 64, text: content});
        }

        function toUtf8(str) {
            var out, i, len, c;
            out = "";
            len = str.length;
            for (i = 0; i < len; i++) {
                c = str.charCodeAt(i);
                if ((c >= 0x0001) && (c <= 0x007F)) {
                    out += str.charAt(i);
                } else if (c > 0x07FF) {
                    out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                    out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
                    out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                } else {
                    out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
                    out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                }
            }
            return out;
        }
    </script>
    <!--
    render   : "canvas",//设置渲染方式
    width       : 256,     //设置宽度
    height      : 256,     //设置高度
    typeNumber  : -1,      //计算模式
    correctLevel    : QRErrorCorrectLevel.H,//纠错等级
    background      : "#ffffff",//背景颜色
    foreground      : "#000000" //前景颜色
     -->
</head>
<body>
输入需要生成的內容：<input id="content" type="text"/>
<input type="button" value="点击获取二維碼" onclick="getQRcode();"/>
<div id="qrcode"></div>
</body>
</html>